package weaver.interfaces.xfjt.action;

import com.weaver.general.BaseBean;
import com.weaver.general.Util;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.interfaces.workflow.action.Action;
import weaver.jobs.xfjt.duss.utils.XfjtUtil;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;

/**
 * @Title: ecology-idea
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2023-03-27
 * @Description: 周期任务发起流程归档创建周期任务反馈流程
 * @ModifyLog:
 **/
public class WeaCycleTaskCreateAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        String requestid = requestInfo.getRequestid();
        String tablename = requestInfo.getRequestManager().getBillTableName();
        String currentDate = DateUtil.getCurrentDate();
        writeLog(">>>>WeaCycleTaskCreateAction>>>requestid=" + requestid);
        RecordSet rs = new RecordSet();
        try {
            rs.executeQuery( "select * from uf_zqrwtz where rwzt=0 and  lcck=?",requestid );
            String [] columnName = rs.getColumnName();
            if (rs.next()) {
                Map<String, String> requestMainMap = new HashMap<>();
                //数据id
                String dataid = Util.null2String( rs.getString( "id" ) );
                //督查重复模式:0-按天重复;1-按周重复;2-按月重复
                String rwzfms = Util.null2String( rs.getString( "rwzfms" ) );
                //每次反馈期限（天）
                int mcwcqxt = Util.getIntValue( rs.getString( "mcwcqxt" ) );
                String lcbh = Util.null2String( rs.getString( "lcbh" ) );
                String rwksrq = Util.null2String( rs.getString( "rwksrq" ) );
                int compDateVal = DateUtil.compDate(currentDate, rwksrq);
                if (compDateVal == 0) {
                    String rwjsrq = Util.null2String( rs.getString( "rwjsrq" ) );
                    String xywcfkrq = DateUtil.addDate(DateUtil.addDate(currentDate,mcwcqxt),-1);
                    String strs = XfjtUtil.getFieldName("-169");
                    for (String column: columnName) {
                        String columnValue = Util.null2String( rs.getString( column ) );
                        if (!"".equals( columnValue ) && strs.contains( column )) {
                            requestMainMap.put( column, columnValue );
                        }
                    }
                    requestMainMap.put("jmid", dataid );
                    requestMainMap.put("gllc", requestid );
                    requestMainMap.put("rwbh", lcbh );
                    requestMainMap.put("zqksrq", rwksrq );
                    requestMainMap.put("zqjsrq", rwjsrq );
                    requestMainMap.put("yqwcrq", xywcfkrq );
                    writeLog( ">>>>>>WeaCycleTaskCreateAction>>>>requestMainMap" + requestMainMap.toString() );
                    switch (rwzfms) {
                        case "0":
                            XfjtUtil.runTaskRntervalDay( currentDate,requestMainMap,dataid );
                            break;
                        case "1":
                            XfjtUtil.runTaskRntervalWeek( currentDate,requestMainMap,dataid );
                            break;
                        case "2":
                            XfjtUtil.runTaskRntervalMonth( currentDate,requestMainMap,dataid );
                            break;
                        default:
                    }  
                }
               
            }
            return Action.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            requestInfo.getRequestManager().setMessageid("111111");
            requestInfo.getRequestManager().setMessagecontent("Action接口异常！");
            return Action.FAILURE_AND_CONTINUE;
        }
    }

}
